home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 235_02 / volume.c < prev   
Text File  |  1987-06-16  |  4KB  |  120 lines

  1. /*  005   2-Jan-87  volume.c
  2.  
  3.          This module contains functions to get and set information about
  4.          DOS disk volumes.
  5.  
  6.          Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  7. */
  8.  
  9. #include <dos.h>
  10.  
  11. #ifndef NULL
  12. #define NULL (0)
  13. #endif
  14.  
  15.  
  16. /******************************************************************************
  17.  **                   C U R R E N T _ D R I V E                              **
  18.  *****************************************************************************/
  19.  
  20. int
  21. current_drive() {      /* return the current drive # in DOS A, B, ... format */
  22.  
  23.    return((bdos(25,0,0) & 0xFF)+'A');
  24. }
  25.  
  26.  
  27. /******************************************************************************
  28.  **                     C H A N G E _ D R I V E                              **
  29.  *****************************************************************************/
  30.  
  31. int
  32. change_drive(drive)    /* changes the current drive */
  33. int drive;
  34. {
  35.  
  36.    return(bdos(14,drive-'A',0));
  37. }
  38.  
  39.  
  40. /******************************************************************************
  41.  **                         G E T V O L S I Z                                **
  42.  *****************************************************************************/
  43.  
  44. getvolsiz(drive,totalp,freep,clszp)    /* return total, free space on volume */
  45. int drive;
  46. unsigned long *totalp, *freep;
  47. unsigned int *clszp;
  48. {
  49.    union REGS r;
  50.    unsigned int clustersiz;
  51.  
  52.    r.h.ah = 54;                /* get disk free space dos int */
  53.    r.h.dl = drive - 'A' + 1;   /* for drive A = 1, B = 2... */
  54.    intdos(&r,&r);
  55.  
  56.    if (r.x.ax != -1) {                         /* -1 if error */
  57.       clustersiz = r.x.ax * r.x.cx;
  58.       *totalp =  (long) clustersiz * r.x.dx;
  59.       *freep  =  (long) clustersiz * r.x.bx;
  60.       *clszp = clustersiz;
  61.    } else {
  62.      *totalp = 0;
  63.      *freep  = 0;
  64.      *clszp  = 0;
  65.    }
  66. }
  67.  
  68.  
  69. /******************************************************************************
  70.  **                         G E T _ S E T _ V O L                            **
  71.  *****************************************************************************/
  72.  
  73. int
  74. get_set_vol(op,np)     /* get and or set the volume label of the current disk */
  75. char *op, *np;
  76. {
  77.    union REGS r;
  78.    char buffer[128];
  79.    static struct {                     /* fcb to search for volume label */
  80.       unsigned char extend;
  81.       unsigned char notused[5];
  82.       unsigned char attribute;
  83.       unsigned char drive;
  84.       unsigned char name[11];
  85.       unsigned char misc[25];
  86.    } fcb = { 0xff, 0, 0, 0, 0, 0, 0x08, 0 };
  87.  
  88.    *op = '\0';                         /* init old name buffer to null string */
  89.  
  90.    bdos(0x1a,buffer,0);                /* set the DTA addr for search */
  91.  
  92.    fcb.drive = 0;                      /* want to use current drive */
  93.    strncpy(fcb.name,"???????????",11); /* set fcb name to wildcard search */
  94.  
  95.    r.h.ah = 17;                        /* search first, fcb */
  96.    r.x.dx = (int) &fcb;                /* offset of the FCB */
  97.    intdos(&r,&r);                      /* let dos do the looking */
  98.  
  99.    if (r.h.al == 0)                    /* al = 0 if found */
  100.       strncat(op,buffer+8,11);         /* put it in the caller's buffer */
  101.  
  102.    if (np != NULL)                     /* is label to be set? */
  103.  
  104.       if (r.h.al == 0) {                       /* is there an existing label? */
  105.          strcpyfill(buffer+24,np,11,' ');      /* move new name to dta */
  106.          r.h.ah = 23;                          /* fcb rename */
  107.          r.x.dx = (int) buffer;
  108.          intdos(&r,&r);
  109.  
  110.       } else {         /* no existing label, create a new one */
  111.  
  112.          strcpyfill(fcb.name,np,11,' ');       /* set new name in fcb */
  113.          r.h.ah = 22;                          /* create file */
  114.          r.x.dx = (int) &fcb;
  115.          intdos(&r,&r);
  116.       }
  117.  
  118.    return(r.h.al == 0xff ? -1 : 0);    /* return 0 if worked okay */
  119. }
  120.